import qs from 'querystring';

// 获取评教准备信息
export const queryQuotaData = () => {
  return new Promise((resolve, reject) => {
    // fetch('/api/getQuotaData')
    fetch('http://localhost:3006/api/getQuotaData')
      .then((res) => res.json())
      .then((res) => {
        resolve(res);
      })
      .catch((error) => {
        reject(error);
      });
  });
};

// 保存评教数据
export const saveQuotaData = (params?: any) => {
  return new Promise((resolve, reject) => {
    fetch('http://localhost:3006/api/saveQuotaData', {
      body: JSON.stringify(params),
      headers: {
        'content-type': 'application/json',
      },
      method: 'POST',
    })
      .then((res) => res.json())
      .then((res) => {
        resolve(res);
      })
      .catch((error) => {
        reject(error);
      });
  });
};

// 获取被评教师信息
export const teacherInfo = () => {
  return new Promise((resolve, reject) => {
    fetch('http://localhost:3006/api/teacherInfo')
      .then((res) => res.json())
      .then((res) => {
        resolve(res);
      })
      .catch((error) => {
        reject(error);
      });
  });
};

// 获取评教信息
export const quotaInfo = () => {
  return new Promise((resolve, reject) => {
    fetch('http://localhost:3006/api/quotaInfo')
      .then((res) => res.json())
      .then((res) => {
        resolve(res);
      })
      .catch((error) => {
        reject(error);
      });
  });
};

// 保存评教结果数据
export const saveTeachingEvaluationResult = (params?: any) => {
  return new Promise((resolve, reject) => {
    fetch('http://localhost:3006/api/saveTeachingEvaluationResult', {
      body: JSON.stringify(params),
      headers: {
        'content-type': 'application/json',
      },
      method: 'POST',
    })
      .then((res) => res.json())
      .then((res) => {
        resolve(res);
      })
      .catch((error) => {
        reject(error);
      });
  });
};

// 获取学期和学年信息
export const getSchoolYearsData = () => {
  return new Promise((resolve, reject) => {
    fetch(`http://localhost:3006/api/schoolYears`)
      .then((res) => res.json())
      .then((res) => {
        resolve(res);
      })
      .catch((error) => {
        reject(error);
      });
  });
};

// 获取教师评教结果数据
export const getTeacherTeachingEvaluationResult = (params?: any) => {
  return new Promise((resolve, reject) => {
    fetch(`http://localhost:3006/api/teacherTeachingEvaluation?${qs.stringify(params)}`)
      .then((res) => res.json())
      .then((res) => {
        resolve(res);
      })
      .catch((error) => {
        reject(error);
      });
  });
};

// 获取院系评教结果统计数据
export const getCollegesResult = (params?: any) => {
  return new Promise((resolve, reject) => {
    fetch(`http://localhost:3006/api/collegesResult?${qs.stringify(params)}`)
      .then((res) => res.json())
      .then((res) => {
        resolve(res);
      })
      .catch((error) => {
        reject(error);
      });
  });
};
